/*
 * Copyright © 2004-2014 chenYuan. All rights reserved.
 * @Website:wwww.jspx.net
 * @Mail:39793751@qq.com
 * @author: chenYuan , 陈原
 * @License: Jspx.net Framework Code is open source (LGPL)，Jspx.net Framework 使用LGPL 开源授权协议发布。
 * @jvm:jdk1.6+  x86/amd64
 *
 */
package com.jspx.scriptmark.core.dispose;

import com.jspx.scriptmark.Phrase;
import com.jspx.scriptmark.core.EnvRunner;
import com.jspx.scriptmark.core.TagNode;
import com.jspx.scriptmark.exception.ScriptRunException;

import java.io.Writer;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: chenYuan
 * Date: 2009-1-2
 * Time: 16:25:35
 */
public class ElsePhrase implements Phrase {

    public int getRun(EnvRunner env, TagNode tagNode, Writer out) throws Exception {
        List<TagNode> list = tagNode.getChildList();
        if (list == null || list.isEmpty()) return 0;
        int bc = 0;
        for (TagNode node : list) {
            try {
                bc = env.runBlock(node, out);
            } catch (Exception e) {
                throw new ScriptRunException(node, node.getTagName());
            }
            if (bc != 0) break;
        }
        list.clear();
        return bc;
    }
}